home *** CD-ROM | disk | FTP | other *** search
- /* ==============
- * V3DPanePort.cc
- * ==============
- */
-
- #include "PedestalDebugging.h"
-
- #include <MacWindows.h>
-
- #include "V3DPanePort.hh"
-
- #include "Ped1AppProcess.hh"
- #include "PedApplication.hh"
- #include "PedView.hh"
-
- #include "C3DObjects.hh"
- #include "C3DPort.hh"
-
-
- V3DPanePort::V3DPanePort(PedView &inSuperView, C3DModel &inModel)
- : PedPane(inSuperView), mPort(NULL)
- {
- mPort = new C3DPort(inModel);
- C3DCamera *camera = new C3DCamera;
- camera->viewAngle = 2 / 1.0;
- mPort->SetCamera(camera);
- }
-
- V3DPanePort::~V3DPanePort()
- {
- }
-
- void
- V3DPanePort::Init()
- {
- if (!mPort) {
- }
- }
-
- void
- V3DPanePort::Open()
- {
- if (!mPort) {
- Init();
- }
-
- PedPane::Open();
-
- //::SetPort(macWindow);
- }
-
- void
- V3DPanePort::Close()
- {
- if (mPort) {
- delete mPort;
- mPort = NULL;
- }
-
- PedPane::Close();
- }
-
- void
- V3DPanePort::Activate()
- {
- }
-
- void
- V3DPanePort::Deactivate()
- {
- }
-
- void
- V3DPanePort::Resize(short inWidth, short inHeight)
- {
- PedPane::Resize(inWidth, inHeight);
-
- //if (mSuperView.IsOpen())
- // ::InvalRect(&mBounds);
- }
-
- void
- V3DPanePort::Draw()
- {
- //PedWindow::Draw();
-
- if (!mPort) return;
-
- ::EraseRect(&qd.thePort->portRect);
-
- // Plot the images in screen coordinates
- mPort->GetCameraFrame();
- C3DPoint *pt = mPort->mPoints.FirstDatum();
- while (pt) {
- double x, y, z;
- Point ptMac;
- short width, height;
-
- width = qd.thePort->portRect.right - qd.thePort->portRect.left;
- height = qd.thePort->portRect.bottom - qd.thePort->portRect.top;
-
- x = pt->Cell(0, 0);
- //y = pt->Cell(0, 1);
- z = pt->Cell(0, 2);
-
- // Use height as coefficient
- ptMac.h = height * x + width / 2;
- ptMac.v = height - (height * z + height / 2);
-
- PenSize(2, 2);
- MoveTo(ptMac.h, ptMac.v);
- Line(0, 0);
-
- // We need a list iterator!
- pt = mPort->mPoints.Successor(pt);
- }
- }
-
- void
- V3DPanePort::DispatchNullEvent(EventRecord &inEvent)
- {
- ::GlobalToLocal(&inEvent.where);
- if (::PtInRect(inEvent.where, &qd.thePort->portRect)) {
- CursHandle cursCross = ::GetCursor(crossCursor);
- ThrowIfNULL_(cursCross);
- ::SetCursor(*cursCross);
- } else
- ::SetCursor(&qd.arrow);
- if (mPort) {
- //mPort->Animate();
- //mSuperView->Focus();
- //Draw();
- }
- }
-
- void
- V3DPanePort::DispatchClickEvent(EventRecord &inEvent)
- {
- if (mPort == NULL)
- return;
-
- //::SetPort(macWindow);
- ::GlobalToLocal(&inEvent.where);
- //::TEClick(inEvent.where, inEvent.modifiers & shiftKey != 0, macTE);
- }
-
- void
- V3DPanePort::DispatchKey(EventRecord &inEvent)
- {
- char c = inEvent.message & charCodeMask;
- if (0) {
- short code = (inEvent.message & keyCodeMask) >> 8;
- } else {
- DoKey(c);
- }
- }
-
- void
- V3DPanePort::DoKey(char inChar)
- {
- if (mPort) {
- short cmd;
- switch (inChar) {
- case '7':
- cmd = cmdMoveLeft;
- break;
- case '9':
- cmd = cmdMoveRight;
- break;
- case '4':
- cmd = cmdYawLeft;
- break;
- case '6':
- cmd = cmdYawRight;
- break;
- case '1':
- cmd = cmdRollLeft;
- break;
- case '3':
- cmd = cmdRollRight;
- break;
- case '8':
- cmd = cmdPitchDown;
- break;
- case '5':
- cmd = cmdPitchUp;
- break;
- case '0':
- cmd = cmdMoveForward;
- break;
- case '.':
- cmd = cmdMoveBackward;
- break;
- case '-':
- cmd = cmdMoveUp;
- break;
- case '+':
- cmd = cmdMoveDown;
- break;
- case '*':
- cmd = cmdExpand;
- break;
- case '/':
- cmd = cmdContract;
- break;
- default:
- break;
- }
- mPort->SendCameraCommand(cmd);
- mSuperView.Focus();
- Draw();
- }
- }
-